package com.onec.service.netty.byteBuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;

public class DircetByteBuf {


  public static void main(String[] args) {

    ByteBuf byteBuf = ByteBufAllocator.DEFAULT.directBuffer();
    byteBuf.writeBytes("我是草香欣二".getBytes());
    if (!byteBuf.hasArray()) {
      int length = byteBuf.readableBytes();
      System.out.println(length);

      // 读取到堆内存再做处理
      byte[] bytes = new byte[length];
      byteBuf.getBytes(byteBuf.readerIndex(), bytes);
      System.out.println("--" + new String(bytes));
    }
    byteBuf.release();

    Unpooled.compositeBuffer();
  }
}
